package com.mia.props.common;

import com.mia.props.Props;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagIntArray;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;

public class TileFake extends TileEntity {
   public int[] master = new int[3];

   public void setMasterTile(TileProps master) {
      this.master[0] = master.xCoord;
      this.master[1] = master.yCoord;
      this.master[2] = master.zCoord;
   }

   public boolean shouldRenderInPass(int pass) {
      return false;
   }

   public boolean canUpdate() {
      return false;
   }

   public TileProps getMaster() {
      TileEntity tile = Props.getTileEntityWithoutCreating(this.worldObj, this.master[0], this.master[1], this.master[2]);
      if (!(tile instanceof TileProps)) {
         this.worldObj.setBlockToAir(this.xCoord, this.yCoord, this.zCoord);
         this.invalidate();
         return null;
      } else {
         return (TileProps)tile;
      }
   }

   public void readFromNBT(NBTTagCompound compound) {
      super.readFromNBT(compound);
      this.master = compound.getIntArray("master");
   }

   public void writeToNBT(NBTTagCompound compound) {
      super.writeToNBT(compound);
      NBTTagIntArray masterTag = new NBTTagIntArray(this.master);
      compound.setTag("master", masterTag);
   }

   public Packet getDescriptionPacket() {
      NBTTagCompound nbttagcompound = new NBTTagCompound();
      this.writeToNBT(nbttagcompound);
      return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, -1, nbttagcompound);
   }

   public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
      this.readFromNBT(pkt.func_148857_g());
   }
}
